﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QLChoDiaOc.Process;

namespace QLChoDiaOc.Forms
{
    /// <summary>
    /// Interaction logic for FormLoaiNhanVien.xaml
    /// </summary>
    public partial class FormLoaiNhanVien : Page
    {
        UpdateInfo _updateInfo = new UpdateInfo();
        ShowInfo _showInfo = new ShowInfo();

        static bool m_bSelectData = false;

        public FormLoaiNhanVien()
        {
            InitializeComponent();
            _showInfo.ShowLoaiNhanVien(dataLoaiNhanVien);
        }

        private void btnThemLoaiNhanVien_Click(object sender, RoutedEventArgs e)
        {
            tenLoaiNVTextBox.Text = "";
            maLoaiNVTextbox.Text = "";
            WinLoaiNhanVien _temp = new WinLoaiNhanVien();
            _temp.Show();
        }

        private void btnSuaLoaiNhanVien_Click(object sender, RoutedEventArgs e)
        {
            if (tenLoaiNVTextBox.Text == "")
                MessageBox.Show("Chưa nhập đầy đủ thông tin", "Thông Báo");
            else
            {
                _updateInfo.UpdateLoaiNhanVien(maLoaiNVTextbox.Text, tenLoaiNVTextBox.Text);
                if (!m_bSelectData)
                    m_bSelectData = true;
                maLoaiNVTextbox.Text = "";
                tenLoaiNVTextBox.Text = "";
                dataLoaiNhanVien.ItemsSource = null;

                _showInfo = new ShowInfo();
                _showInfo.ShowLoaiNhanVien(dataLoaiNhanVien);
            }
        }

        private void bntReloadNhanVien_Click(object sender, RoutedEventArgs e)
        {
            if (!m_bSelectData)
                m_bSelectData = true;
            maLoaiNVTextbox.Text = "";
            tenLoaiNVTextBox.Text = "";
            dataLoaiNhanVien.ItemsSource = null;

            _showInfo = new ShowInfo();
            _showInfo.ShowLoaiNhanVien(dataLoaiNhanVien);
        }

        private void dataLoaiNhanVien_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!m_bSelectData)
            {
                var item = dataLoaiNhanVien.SelectedItem as LOAINHANVIEN;

                maLoaiNVTextbox.Text = item.MaLoaiNV;
                tenLoaiNVTextBox.Text = item.TenLoaiNV;
            }
            else
            {
                m_bSelectData = false;
                _showInfo = new ShowInfo();
                _showInfo.ShowLoaiNhanVien(dataLoaiNhanVien);
            }
        }
    }
}
